package xyz.shuixiangyu.core;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import xyz.shuixiangyu.movie.Movie;
import xyz.shuixiangyu.movie.MovieReader;

public class FilmDirectoryGenerator {
	private final String src;
	private final String des;
	
	public FilmDirectoryGenerator(String src, String des) throws FileNotFoundException  {
		super();
		if(check(src)&&check(des)){
			this.src = src;
			this.des = des;			
		}else{
			this.src = "";
			this.des = "";
		}
	}
	
	public void start(){
		MovieReader reader=new MovieReader(src);
		List<Movie> movies=reader.getMovies();
		try {
			FilmDirectoryWorker fw=new FilmDirectoryWorker(des);
			fw.add(movies);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	private boolean check(String filePath) throws FileNotFoundException{
		if(!new File(filePath).exists()){
			throw new FileNotFoundException(filePath+" does not exist!");
		}
		return true;
	}
}
